<template>
  <div class="goods-list">
    <el-card shadow="never">
      <el-form ref="searchForm" :model="form" label-width="100px" label-position="right">
        <el-row>
          <el-col :md="8">
            <el-form-item label="姓名">
              <el-input
                v-model="form.realName"
                clearable
                placeholder="请输入师傅姓名"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="手机号">
              <el-input
                v-model="form.phone"
                clearable
                placeholder="请输入师傅手机号"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="身份证号码">
              <el-input
                v-model="form.idCard"
                clearable
                placeholder="请输入身份证号码"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="师傅状态">
              <el-select v-model="form.status" clearable placeholder="请选择师傅状态">
                <el-option v-for="item in statusData" :key="item.value" :label="item.name" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item label="登记日期">
              <el-date-picker
                v-model="times"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
          </el-col>
          <el-col :md="8">
            <el-form-item align="right">
              <el-button type="primary" @click="getWorkerList()">查 询</el-button>
              <el-button plain @click="resetForm()">重 置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="supplierBtn">
        <el-button type="success" @click="$showNoAuthMsg()">数据下载</el-button>
        <el-button type="warning" @click="$showNoAuthMsg()">数据导入</el-button>
        <el-button type="danger" @click="$showNoAuthMsg()">操作记录</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        stripe
        :header-cell-style="{background:'#f2f3f5',color:'#606266'}"
        class="table-data"
      >
        <el-table-column type="selection" align="center" width="55" />
        <el-table-column prop="userId" label="编号" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="realName" label="姓名" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="phone" label="手机号" align="center" :show-overflow-tooltip="true" min-width="150" />
        <el-table-column prop="idCard" label="身份证号" align="center" :show-overflow-tooltip="true" min-width="180" />
        <el-table-column prop="areaDetails" label="工作区域" align="center" :show-overflow-tooltip="true" min-width="150">
          <template slot-scope="scope">
            <span> {{ scope.row.areaDetails.join(',') }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="categoryDetails" label="服务品类" align="center" :show-overflow-tooltip="true" min-width="150">
          <template slot-scope="scope">
            <span> {{ scope.row.categoryDetails.join(',') }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="账号状态" align="center" :show-overflow-tooltip="true" min-width="150">
          <template slot-scope="scope">
            <span> {{ scope.row.status == 0 ? '锁定' : '正常' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="gmtCreate" label="登记日期" align="center" :show-overflow-tooltip="true" min-width="180">
          <template slot-scope="scope">
            <span> {{ formatTimes(scope.row.gmtCreate,"YYYY/MM/DD hh:mm:ss") }}</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="viewExamine(scope.row)">查 看</el-button>
            <el-button v-if="scope.row.status == 1" type="text" size="small" @click="lock(scope.row)">锁 定</el-button>
            <el-button v-if="scope.row.status == 0" type="text" size="small" @click="unlock(scope.row)">解 锁</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
          :page-size="page.pageSize"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :current-page.sync="page.pageNo"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { getWorkerList, workerEnable, workerDisable } from '@/api/worker'
import { formatTimes } from '@/utils'
export default {
  data() {
    return {
      formatTimes,
      form: {},
      tableData: [],
      loading: false,
      statusData: [
        { value: null, name: '全部' },
        { value: 0, name: '无效' },
        { value: 1, name: '有效' }
      ],
      times: [],
      page: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  computed: {
  },
  mounted() {
    this.getWorkerList()
  },
  methods: {
    // 获取师傅列表
    async getWorkerList() {
      try {
        this.loading = true
        const parmas = {
          ...this.form,
          startDate: this.times && this.times.length > 0 ? this.times[0] : '',
          endDate: this.times && this.times.length > 0 ? this.times[1] : '',
          ...this.page
        }
        const res = await getWorkerList(parmas)
        this.loading = false
        this.tableData = res.objects
        this.page.total = res.total
      } catch (error) {
        console.log(error)
        this.loading = false
      }
    },
    // 重置搜索
    resetForm() {
      this.$nextTick(() => {
        this.form = {}
        this.times = []
      })
    },
    // 锁定
    async lock(row) {
      if (process.env.VUE_APP_PACKAGE === 'externalize') {
        try {
          await this.$confirm('亲，这是演示版，你没有权限!,想获得所有权限，请联系咨询老师，获取代码', '系统提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
        } catch (error) {
          console.log(error)
        }
        return
      }
      try {
        const formData = new FormData()
        formData.append('id', row.id)
        await workerDisable(formData)
        this.getWorkerList()
        this.$message.success('操作成功！')
      } catch (error) {
        console.log(error)
      }
    },
    // 解锁
    async unlock(row) {
      if (process.env.VUE_APP_PACKAGE === 'externalize') {
        try {
          await this.$confirm('亲，这是演示版，你没有权限!,想获得所有权限，请联系咨询老师，获取代码', '系统提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
        } catch (error) {
          console.log(error)
        }
        return
      }
      try {
        const formData = new FormData()
        formData.append('id', row.id)
        await workerEnable(formData)
        this.getWorkerList()
        this.$message.success('操作成功！')
      } catch (error) {
        console.log(error)
      }
    },
    // 查看审核
    viewExamine(row) {
      this.$router.push({
        path: '/examine/status/detail',
        query: {
          userId: row.userId,
          isExamine: false
        }
      })
    },
    // 切换条
    handleSizeChange(val) {
      this.page.pageSize = val
      this.getWorkerList()
    },
    // 切换页
    handleCurrentChange(val) {
      this.page.pageNo = val
      this.getWorkerList()
    }
  }
}
</script>
<style lang="scss" scoped>
.el-select{
  width: 100%;
}
.table-data{
  margin: 30px 0px;
}
.el-date-editor{
  width: 100%;
}
.pagination{
  text-align: right;
}
</style>
